#include <iostream>

using namespace std;

long ntest, f, a, b, c, result;

int main()
{
	cin >> ntest;
	while (0 < ntest--)
	{
		cin >> f;
		result = 0;
		for (int i = 0; i < f; i++)
		{
			cin >> a >> b >> c;
			result += a*c;
		}
		cout << result << endl;
	}
	return 0;
}
